/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.ufrn.aipetro.ga.view.form;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import br.com.ufrn.aipetro.ga.controller.interfaces.Controller;
import br.com.ufrn.aipetro.ga.domain.entity.interfaces.Model;
import br.com.ufrn.aipetro.ga.view.interfaces.View;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.effect.BlendMode;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

/**
 *
 * @author Andre
 */
public class ControllerAipetro implements Initializable{

    @FXML private Button sensores;
    @FXML private static TabPane tabs;
    @FXML private AnchorPane anchor;
    @FXML private Button btTeste;
    @FXML private HBox hbox;
    @FXML private TextField testeBinding;
    @FXML private TextArea txtBinding;
    
    @FXML
    private void showSensores(ActionEvent event) throws Exception {
        sensores.setText("teste");
        System.out.println("teste");
        
        
//        Stage stage = new Stage();
//        Scene scene = (Scene)FXMLLoader.load(getClass().getResource("aipetro.fxml"));
//        //Scene scene = new Scene(root);
//        stage.setScene(scene);
//        stage.show();
        Parent root = FXMLLoader.load(getClass().getResource("ControladorFXML.fxml"));
        
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
//        tab.setContent(new Rectangle(200,200, Color.LIGHTSTEELBLUE));
        tabs.getTabs().add(tab);
//        tabs.getTabs().remove(0);
    }
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
    }

    @FXML
    private void showFormController() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("FormController.fxml"));
        Tab tab = new Tab();
        tab.setText("Controlador");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showFormMesh() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("FormMesh.fxml"));
        Tab tab = new Tab();
        tab.setText("Malha");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showFormOperationStatus() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("FormOperationStatus.fxml"));
        Tab tab = new Tab();
        tab.setText("Status");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showFormPlant() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("FormPlant.fxml"));
        Tab tab = new Tab();
        tab.setText("Planta");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showFormProtocol() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("FormProtocol.fxml"));
        Tab tab = new Tab();
        tab.setText("Protocolo");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showFormSensor() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("aFormValve.fxml"));
        Tab tab = new Tab();
        tab.setText("Sensor");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showFormUnit() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("FormUnit.fxml"));
        Tab tab = new Tab();
        tab.setText("Unidade");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showFormValve() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("FormValve.fxml"));
        Tab tab = new Tab();
        tab.setText("V�lvula");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showMaintenanceSchedule() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../maintenance/MaintenanceSchedule.fxml"));
        Tab tab = new Tab();
        tab.setText("Nota de Servi�o");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showServiceOrder() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../maintenance/ServiceOrder.fxml"));
        Tab tab = new Tab();
        tab.setText("Ordem de Servi�o");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSearchController() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../search/SearchController.fxml"));
        Tab tab = new Tab();
        tab.setText("Pesquisa Controlador");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSearchMesh() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../search/SearchMesh.fxml"));
        Tab tab = new Tab();
        tab.setText("Pesquisa Malha");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSearchOperationStatus() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../search/SearchOperationStatus.fxml"));
        Tab tab = new Tab();
        tab.setText("Pesquisa Status");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSearchServiceNote() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../search/SearchServiceNote.fxml"));
        Tab tab = new Tab();
        tab.setText("Pesquisa Nota de Servi�o");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSearchPlant() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../search/SearchPlant.fxml"));
        Tab tab = new Tab();
        tab.setText("Pesquisa Planta");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSearchProtocol() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../search/SearchProtocol.fxml"));
        Tab tab = new Tab();
        tab.setText("Pesquisa Protocolo");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSearchUnit() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../search/SearchUnit.fxml"));
        Tab tab = new Tab();
        tab.setText("Pesquisa Unidade");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSearchValve() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../search/SearchValve.fxml"));
        Tab tab = new Tab();
        tab.setText("Pesquisa V�lvula");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showController() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("PlantFXML.fxml"));
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showCadPlant() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("PlantFXML.fxml"));
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showPesqPlant() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("SearchPlant.fxml"));
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showPesqProtocol() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("SearchProtocol.fxml"));
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showMesh() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("MeshFXML.fxml"));
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showCadController() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("ControllerFXML.fxml"));
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSensor() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("SensorFXML.fxml"));
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showValve() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("ValveFXML.fxml"));
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showOperationStatus() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("ControllerSearchFXML.fxml"));
        Tab tab = new Tab();
        tab.setText("new tab");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showFinance() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("FormFinance2.fxml"));
        Tab tab = new Tab();
        tab.setText("Finan�as");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    @FXML
    private void showSearchMaintenance() throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("../search/SearchMaintenance.fxml"));
        Tab tab = new Tab();
        tab.setText("Manutencao");
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    
    public static void showTab(URL resourceFxml, String tabTitle, Controller controller, Model model) throws IOException {
    	FXMLLoader loader = new FXMLLoader(resourceFxml);
    	Parent root = (Parent)loader.load();
    	
    	View view = (View)loader.getController();
    	view.initView(controller);
    	controller.setModel(model);
        
    	
//    	Parent root = FXMLLoader.load(resourceFxml);
        Tab tab = new Tab();
        tab.setText(tabTitle);
        tab.setContent(root);
        tabs.getTabs().add(tab);
        tabs.getSelectionModel().select(tab);
    }
    
    
    @FXML
    private void centerButtons() {
        txtBinding.textProperty().bind(testeBinding.textProperty());
    }
}
